{
 "metadata": {
  "name": "",
  "signature": "sha256:9cc7511c92987842b7202eeacd0746e1d444ef3851fca6c3f3019ff3363eeaff"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import operator\n",
      "import matplotlib.pyplot as plt\n",
      "%matplotlib inline"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 19
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "rd = np.random.randn(100) * 10 \n",
      "x1 = np.linspace(0, 10, 100)\n",
      "y1 = np.random.rand(100) + rd\n",
      "\n",
      "\n",
      "x2 = np.linspace(10, 20, 100)\n",
      "y2 = np.random.rand(100) + rd\n",
      "\n",
      "def plot(x1, y1, x2, y2):\n",
      "    scatter0 = plt.scatter(x1, y1, c='b', marker='o')\n",
      "    scatter1 = plt.scatter(x2, y2, c='r', marker='x')\n",
      "    plt.legend(handles=[scatter0, scatter1], labels=['label0','label1'],loc='best')\n",
      "    \n",
      "plot(x1, y1, x2, y2)\n",
      "plt.show() "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJztnX2MHdWZ5p/XdhtvDx9tGsJ4Md1N\n1hExnw20cFhYmAQIDpqNMyPPhlUnCwORFZKh2yarwcSS6Yxi7ZBoMfaS7Mo7RDHrzoRd7xKi0YwI\nJF6hKIGZNjIMBBwMcXvbcsA4mARZBLv73T+qyl23uj5OVZ1z6lTV+5NKfatu3apTdfs+563nvOcc\nYmYIgiAIzWde1Q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w+Vd+3O+A9mcWR\n9Z2b4C98q+k7CRZFlffr3wB4k5lfS3jf+P2K6EJl/191E3ynIaJTAfxvAGuZ+beRt5+HZ1tcBuC/\nAPiBpWJdy8xXAPgUgC8T0XWWzpsJES0E8GkA/yvm7aruVwfsPV87lcpGRBsAnAAwnrCL7e/8vwL4\nVwAGARyCZ5+4xL9HenRv9H6l6YLt/6+6Cf5BAOeF1pf622L3IaIFAM4AcMR0wYioC96XOs7M/yf6\nPjP/lpnf81//PYAuIjrLdLmY+aD/9y0Aj8N7tA6jck9N8SkAzzPzm9E3qrpfPm8Gtpb/962YfSq5\nb0R0O4A/BjDsi8UcFL5zrTDzm8w8zcwzAP57wvmqul8LAPwpgMeS9jF5vxJ0obL/r7oJ/j8B+AgR\nne9Hh7cC+GFknx8CCFq0VwP4SdIPQxe+R/gIgFeY+cGEff4waEsgoqvg3XujFRER/QERnRa8htfo\n91Jktx8C+A/k8TEA74YeN02TGHlVcb9ChP+HbgPwRMw+TwL4JBEt9i2MT/rbjEFEKwH8JYBPM/Ox\nhH1UvnPd5Qq3+fxJwvlUfrsmuBHAq8w8FfemyfuVogvV/X/pbpk2vcDLKvklvBb/Df62v4L3IwCA\nRfAsgn0A/hHAhy2U6Vp4j2UvAtjjL7cA+CKAL/r7/AWAl+FlJzwL4F9bKNeH/fO94J87uF/hchGA\nb/n3858BDFn6Hv8AnoCfEdpm/X7Bq3AOATgOzye9E16bz48BvAbgaQBn+vsOAfib0Gfv8P/P9gH4\ncwvl2gfP1w3+x4JstH8J4O/TvnPD5fof/v/Oi/DEbEm0XP76nN+uyXL5278b/E+F9rVyv1J0obL/\nL+lpKwiC0BLqZukIgiAIBRHBFwRBaAki+IIgCC1BBF8QBKEliOALgiC0BBF8QRCEliCCLwiC0BJE\n8AVBEFrC/wcyrbcjIGvuHwAAAABJRU5ErkJggg==\n",
       "text": [
        "<matplotlib.figure.Figure at 0x7f6d723f0400>"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def knn(K, center, data, label):\n",
      "    center = np.tile(center,(data.shape[0],1))\n",
      "    diff = np.sqrt(np.sum((center - data)**2, axis = 1))\n",
      "    #print (diff.shape)\n",
      "    index = diff.argsort()\n",
      "    label_dict = dict()\n",
      "    for i in range(K):\n",
      "        result = label[index[i]]\n",
      "        label_dict[result] = label_dict.get(result, 0) + 1\n",
      "    label_dict = sorted(label_dict.items(), key=operator.itemgetter(1), reverse=True)\n",
      "    return (label_dict[0][0])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 21
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x_data = np.hstack((x1,x2))\n",
      "y_data = np.hstack((y1,y2))\n",
      "#print (x_data.shape)\n",
      "data = np.hstack((x_data.reshape(-1,1),y_data.reshape(-1,1)))\n",
      "#print (data.shape)\n",
      "label = [\"A\"]*100 + [\"B\"]*100\n",
      "center = np.array([10, 2])\n",
      "K = 50\n",
      "print (\"The result is: \", knn(K, center, data,label))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "<class 'numpy.ndarray'>\n",
        "The result is:  B\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 22
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}